package com.principal;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.dao.PersonaDAO;
import com.interfaz.Login;
import com.interfaz.VentanaIngreso;
import com.modelo.Persona;

public class Iniciar {
	public static void main(String [] args){
		Login login = new Login();
		//VentanaIngreso vi = new VentanaIngreso();
		//cargarContexto();
		//sha256("123456");
		//md5Java("martin");
	}
	public void escribeAlgo(){
		System.out.println("Segundo metodo clase principal");
		
	}
	public static void cargarContexto(){
		System.out.println("Constructor Iniciar()");
		
		   ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
		   PersonaDAO ip = ctx.getBean("personaDao",PersonaDAO.class);
		   Persona persona = new Persona();
		   persona.setApellido("Perez");
		   persona.setNombre("luis");
		   persona.setDireccion("Direccio");
		   persona.setDni("12345678");
		   ip.insertar(persona);
		    

	    		
	}
	//Es de un camino, se codifica pero no decodifica.
	public static String sha256(String base) {
		base = "123456";
	    try{
	        MessageDigest digest = MessageDigest.getInstance("SHA-256");
	        byte[] hash = digest.digest(base.getBytes("UTF-8"));
	        StringBuffer hexString = new StringBuffer();

	        for (int i = 0; i < hash.length; i++) {
	            String hex = Integer.toHexString(0xff & hash[i]);
	            if(hex.length() == 1) hexString.append('0');
	            hexString.append(hex);
	        }
	        System.out.println(hexString.toString());
	        return hexString.toString();
	    } catch(Exception ex){
	       throw new RuntimeException(ex);
	    }
	}
	
	
}
